var Url = "https://program.chinlingcloud.com/index.php/api/v2/";
    bodyHeight()

    function bodyHeight() {
        var bodyHeight = $(document).height();
        $("body").css("height", bodyHeight)
        console.log(screen.height)
        var pageHeight = (bodyHeight)
        $(".page").css("height", pageHeight + "px")
    }

    var hrefText = location.href;
    if (hrefText.indexOf("category") != -1) {
        $("footer").find("li").eq(0).find("img").attr("src", "/static/index/img/icon_home.png")
        $("footer").find("li").eq(0).find("span").removeClass("onspan")
        $("footer").find("li").eq(1).find("img").attr("src", "/static/index/img/icon_cate_selected.png")
        $("footer").find("li").eq(1).find("span").addClass("onspan")
        $("footer").find("li").eq(2).find("img").attr("src", "/static/index/img/icon-information.png")
        $("footer").find("li").eq(2).find("span").removeClass("onspan")
        $("footer").find("li").eq(3).find("img").attr("src", "/static/index/img/icon_cart.png")
        $("footer").find("li").eq(3).find("span").removeClass("onspan")
        $("footer").find("li").eq(4).find("img").attr("src", "/static/index/img/icon_member.png")
        $("footer").find("li").eq(4).find("span").removeClass("onspan")

    }
    getTypeData(1)
    getTypeDataInfo(3)

    function getTypeData(id) {
        $.ajax({
            type: "get",
            url: Url + 'type/' + id,
            async: true,
            timeout : 20000,
            beforeSend: function (xhr) {
                showDiv()
            },
            success: function (data) {
                hiddenDiv()
                console.log(data)
                var str = '';
                for (var i = 0; i < data.length; i++) {
                    str += '<span class="sidebar_span" _id="' + data[i].protype_id + '">' + data[i].protype_name + '</span>';
                }
                $("#sidebar_1").html(str);
                $(".sidebar_span").eq(0).addClass("highlight")
            },
            error: function (request, status, err) {
                failure(status)
            }
        });
    }

    function getTypeDataInfo(id) {
        $.ajax({
            type: "get",
            url: Url + 'type/' + id,
            async: true,
            timeout : 20000,
            beforeSend: function (xhr) {
                showDiv()
            },
            success: function (data) {
                hiddenDiv()
                console.log(data)
                var str = '';
                for (var i = 0; i < data.length; i++) {
                    str += '<a href="list_recommend?id=' + data[i].protype_id + '&protype_name=' + data[i].protype_name + '"><dl>'
                        + '<dt>'
                        + '<image src="' + data[i].protype_img + '"   protype_id="' + data[i].protype_id + '"/>'
                        + '</dt>'
                        + '<dd>'
                        + '<span>' + data[i].protype_name + '</span>'
                        + '</dd>'
                        + '</dl></a>';
                }
                $("#griddivContent").html(str);
            },
            error: function (request, status, err) {
                failure(status)
            }
        });
    }

    getColumnData(3)

    function getColumnData(typeId) {
        $.ajax({
            type: "get",
            url: Url + 'column/' + typeId,
            async: true,
            timeout : 20000,
            beforeSend: function (xhr) {
                showDiv()
            },
            success: function (data) {
                hiddenDiv()
                console.log(data)
                $(".banner").attr("src", data.protype_img)
                $(".expect_content").text(data.protype_name)
            },
            error: function (request, status, err) {
                failure(status)
            }
        });
    }

    $("#sidebar_1").on("click", ".sidebar_span", function () {
        $(this).addClass("highlight");
        $(this).siblings("span").removeClass("highlight");
        var _id = $(this).attr("_id");
        getColumnData(_id);
        getTypeDataInfo(_id)
    })


